home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / asmlib06.zip / ASMLIB06.ASM < prev    next >
Assembly Source File  |  1993-01-04  |  5KB  |  152 lines

  1.     INCLUDE    EXTENDA.INC
  2.  
  3. ;***********************************************************************
  4. ;
  5. ;    Equates
  6. ;
  7.  
  8. $define FALSE            0000H
  9. $define TRUE            0001H
  10.  
  11.     CODESEG    ASMLIB06
  12.     DATASEG
  13.  
  14.  
  15. CLpublic <CURDIR, CURDRV, HOMEDIR>
  16.  
  17. ; storage for full pathname and pointer to address it
  18. CLstatic <byte ASCIIZ <<64 DUP(0)>>, cptr STRING ASCIIZ>
  19.  
  20.  
  21. ;******
  22. ;
  23. ;    CURDIR()
  24. ;
  25. ;    string = CURDIR(drive)
  26. ;
  27. ;        drive:   drive letter (A, B, ...)
  28. ;             :     current drive if omitted.
  29. ;
  30. CLfunc char CURDIR <char drive>
  31.  
  32. CLcode
  33.           PUSH    DS            ; preserve
  34.           PUSH    ES            ; preserve
  35.           LDS    SI, STRING        ; point to mem block
  36.           MOV    BYTE PTR [SI],0    ; null string if error
  37.           MOV    DL, 0            ; assume default drive
  38.  
  39.           TESTNUL    drive        ; test if parameter supplied
  40.           JZ    FILL_ASCIIZ
  41.  
  42.           ; parameter supplied..get specified drive letter
  43.           PUSH    ES            ; preserve
  44.           LES    BX, drive        ; load pointer
  45.           MOV    DL, ES:[BX]        ; get drive letter
  46.           AND    DL, 01011111B    ; ensure upper case
  47.           SUB    DL, ('A' - 1)    ; convert to number ('A' = 1)
  48.           POP    ES            ; restore
  49.  
  50. FILL_ASCIIZ:
  51.           PUSH  SI
  52.           MOV    BYTE PTR [SI],'\'
  53.           INC   SI
  54.           DOSREQ      47H         ; Get current dir. string from DOS
  55.           PUSH  DS
  56.           PUSH  SI
  57.           POP   DI
  58.           POP   ES
  59.           XOR   AX,AX             ; 
  60.           CLD                     ; Scan direction forwards
  61.           MOV   CX,0FFH           ; Max. bytes to scan
  62.           REPNE SCASB             ; Find end of string
  63.           MOV    BYTE PTR [DI],0   ; Mark it
  64.           DEC   DI                ; Move back one
  65.           MOV    BYTE PTR [DI],'\' ; And insert trailing backslash
  66.           POP   SI
  67.           POP    ES            ; restore
  68.           POP    DS            ; restore
  69.  
  70.           ; return pointer to directory path
  71.           CLRET    STRING
  72.  
  73. ;****************************************************************************
  74. ;       CURDRV
  75. ;       This function checks and returns the DOS current disk drive as
  76. ;       an ASCIIZ string.
  77. ;       
  78. ;       Parameters :
  79. ;         None
  80. ;
  81. ;       Returns :
  82. ;         Current drive designation - A:, B:, C:, etc
  83. ;
  84.  
  85. CLFUNC CHAR CURDRV
  86. CLCODE
  87.           LDS   SI, STRING
  88.     DOSREQ      19H               ; Get current drive service.
  89.           ADD   AL,41H                  ; Convert digit to a letter
  90.           MOV   DS:[SI+0],AL            ; and move it into the buffer.
  91.           MOV   AL,':'                  ; Append a colon
  92.           MOV   DS:[SI+1],AL            ; after the drive letter.
  93.           MOV   AL,0                    ; Then null terminate
  94.           MOV   DS:[SI+2],AL            ; the string
  95.           CLRET STRING                  ; and return it to Clipper.
  96.  
  97. ;****************************************************************************
  98. ;       HOMEDIR
  99. ;       This function returns the program home directory (the directory
  100. ;         in which the program is located) as an ASCIIZ string.
  101. ;       
  102. ;       Parameters :
  103. ;         None
  104. ;
  105. ;       Returns :
  106. ;         the program home directory as an ASCIIZ string.
  107.  
  108. CLFUNC    CHAR  HOMEDIR
  109. CLCODE
  110.     DOSREQ      62H         ; Get PSP segment in BX
  111.           PUSH  BX                ; and move it
  112.           POP   DS                ; into DS.
  113.           MOV   CX,DS:2CH         ; Get environment block segment pointer
  114.           PUSH  CX                ; from DS:2CH into CX and then move it
  115.           POP   ES                ; into ES.
  116.           XOR   DI,DI             ; Start at beginning of block
  117.           XOR   AX,AX             ; and scan for a null (0H).
  118.           CLD                     ; Scan direction forwards.
  119.  
  120. HOME1:
  121.           REPNE SCASB             ; Now scan string.
  122.           CMP   AL,ES:[DI]        ; Is byte past end another null?
  123.           JNE   HOME1             ; No, more strings left, go around.
  124.           ADD   DI,3              ; Else skip over strings count word.
  125.  
  126.           PUSH  ES                ; Save string base.
  127.           PUSH  DI                ; Save string offset.
  128.           MOV   BX,DI             ; and copy it to BX.
  129.           REPNE SCASB             ; Scan string.
  130.           MOV   AL,'\'            ; Now to strip off filename.
  131.           STD                     ; Scan direction is backwards.
  132.           REPNE SCASB             ; Scan string
  133.           CLD                     ; Scan direction forwards again.
  134.           ADD   DI,2              ; Adjust DI offset for overshoot.
  135.           MOV   CX,DI             ; Move it into CX, and 
  136.           SUB   CX,BX             ; Subtract BX to get string length.
  137.           POP   SI                ; Restore string offset as source offset.
  138.           POP   DS
  139.  
  140.           MOV   AX,DGROUP         ; Get DGROUP segment address
  141.           MOV   ES,AX             ; and move it to ES.
  142.           LEA   DI,ASCIIZ         ; Then get buffer offset in DI
  143.           REP   MOVSB             ; and copy string into it.
  144.           MOV   AL,0              ; Now stick a null terminator
  145.           MOV   ES:[DI],AL        ; onto the end of the string.
  146.           LEA   DI,ASCIIZ         ; Get starting offset again,
  147.           SES   DI,STRING         ; and store pointer to buffer in STRING.
  148.           CLRET STRING            ; Return it to Clipper
  149.  
  150.         END
  151.  
  152.